/*
 * LiquidBounce Hacked Client
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
 * https://github.com/CCBlueX/LiquidBounce/
 */
package net.ccbluex.liquidbounce.features.module.modules.exploit

import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.ModuleCategory
import net.ccbluex.liquidbounce.features.module.ModuleInfo
import net.ccbluex.liquidbounce.value.FloatValue
import net.ccbluex.liquidbounce.value.ListValue
import kotlin.math.cos
import kotlin.math.sin

@ModuleInfo(name = "Clip", description = "Allows you to clip through blocks.", category = ModuleCategory.EXPLOIT, canEnable = false)
class Clip : Module() {

    private val modeValue = ListValue("Mode", arrayOf("Teleport", "Flag"), "Teleport")
    private val horizontalValue = FloatValue("Horizontal", 0F, -10F, 10F)
    private val verticalValue = FloatValue("Vertical", 5F, -10F, 10F)

    override fun onEnable() {
        val thePlayer = mc.thePlayer ?: return

        val yaw = Math.toRadians(thePlayer.rotationYaw.toDouble())
        val x = -sin(yaw) * horizontalValue.get()
        val z = cos(yaw) * horizontalValue.get()

        when (modeValue.get().toLowerCase()) {
            "teleport" -> thePlayer.setPosition(thePlayer.posX + x, thePlayer.posY + verticalValue.get(),
                    thePlayer.posZ + z)

            "flag" -> {
                val netHandler = mc.netHandler

                netHandler.addToSendQueue(classProvider.createCPacketPlayerPosition(thePlayer.posX,
                        thePlayer.posY, thePlayer.posZ, true))
                netHandler.addToSendQueue(classProvider.createCPacketPlayerPosition(0.5, 0.0,
                        0.5, true))
                netHandler.addToSendQueue(classProvider.createCPacketPlayerPosition(thePlayer.posX,
                        thePlayer.posY, thePlayer.posZ, true))
                netHandler.addToSendQueue(classProvider.createCPacketPlayerPosition(thePlayer.posX + x,
                        thePlayer.posY + verticalValue.get(), thePlayer.posZ + z, true))
                netHandler.addToSendQueue(classProvider.createCPacketPlayerPosition(0.5,
                        0.0, 0.5, true))
                netHandler.addToSendQueue(classProvider.createCPacketPlayerPosition(thePlayer.posX
                        + 0.5, thePlayer.posY, thePlayer.posZ + 0.5, true))

                thePlayer.setPosition(thePlayer.posX + -sin(yaw) * 0.04, thePlayer.posY,
                        thePlayer.posZ + cos(yaw) * 0.04)
            }
        }
    }

}